[ThienDuc3112] iP#100
Conversation
Last commit I forgot to add list command
Also error handling
| @@ -0,0 +1,111 @@ | |||
| import java.util.*; | |||
There was a problem hiding this comment.
Avoid using wildcard imports
Import only the functions that you need
| isOn = true; | ||
| datas = new ArrayList<>(); | ||
|
|
||
| String greeting = "____________________________________________________________\n" + |
There was a problem hiding this comment.
use "final" and SCREAMING_SNAKE_CASE for the greeting variable as it is a constant
| return isDone; | ||
| } | ||
|
|
||
| public void mark(){ |
There was a problem hiding this comment.
add a space before the "{" to keep layout consistent
| String line = in.nextLine().strip(); | ||
| System.out.println("____________________________________________________________"); | ||
|
|
||
| if (line.equals("bye")) { |
There was a problem hiding this comment.
Followed if else layout convention. Good job
| @@ -0,0 +1,111 @@ | |||
| import java.util.*; | |||
There was a problem hiding this comment.
Perhaps you could import just the libraries you need?
| } else if (line.equals("list")) { | ||
| list(); | ||
| } else if (line.startsWith("mark ")) { | ||
| mark(line); | ||
| } else if (line.startsWith("unmark ")) { | ||
| unmark(line); | ||
| } else if (line.startsWith("todo ")) { | ||
| todo(line); | ||
| } else if (line.startsWith("event ")) { | ||
| event(line); | ||
| } else if (line.startsWith("deadline ")) { | ||
| deadline(line); | ||
| } else { | ||
| add(line); | ||
| } |
There was a problem hiding this comment.
Perhaps you could refactor this into another function? This chunk is long and hard to read.
|
|
||
| private static void todo(String line) { | ||
| String todo = line.substring(line.indexOf(" ") + 1).trim(); | ||
| Todo task =new Todo(todo); |
|
|
||
| public static void main(String[] args) { | ||
| isOn = true; | ||
| datas = new ArrayList<>(); |
There was a problem hiding this comment.
Perhaps you could use a more descriptive name for your array list, as it is unclear what is being stored here.
| return "[" + | ||
| (isDone ? "X" : " ") + | ||
| "] " + | ||
| task; |
There was a problem hiding this comment.
Perhaps you could write this all in 1 line of code to make your code more readable.
Mahesh1772
left a comment
There was a problem hiding this comment.
Solid effort
Code is following most of the code quality standards. The naming would need to be improved for better scalability so that fellow developers can understand the use of the method and variable easily. Consider adding JavaDocs in future commits
| private static List<Task> taskList; | ||
|
|
||
| public static void main(String[] args) { | ||
| isOn = true; |
There was a problem hiding this comment.
Consider using more descriptive names, that is easily identified to serve a definite purpose
| isOn = false; | ||
| } else if (line.equals("list")) { | ||
| list(); | ||
| } else if (line.startsWith("mark ")) { | ||
| mark(line); | ||
| } else if (line.startsWith("unmark ")) { | ||
| unmark(line); | ||
| } else if (line.startsWith("todo ")) { | ||
| todo(line); | ||
| } else if (line.startsWith("event ")) { | ||
| event(line); | ||
| } else if (line.startsWith("deadline ")) { | ||
| deadline(line); | ||
| } else { | ||
| System.out.println("Unknown command: " + line); | ||
| } |
There was a problem hiding this comment.
Consider using switch case for this case, as the different cases of input is pre-determined
| } | ||
| } | ||
|
|
||
| private static void list() { |
There was a problem hiding this comment.
Consider naming it as listTasks to avoid confusion with the inbuilt type
| int option = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| taskList.get(option - 1).mark(); | ||
| System.out.println(taskList.get(option - 1).toString()); | ||
| } catch (Exception e) { | ||
| System.out.println("Invalid input, input must be a positive integer and must exist"); | ||
| } | ||
| } | ||
|
|
||
| private static void unmark(String line) { | ||
| try { | ||
| int option = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| taskList.get(option - 1).unmark(); | ||
| System.out.println(taskList.get(option - 1).toString()); | ||
| } catch (Exception e) { | ||
| System.out.println("Invalid input, input must be a positive integer and must exist"); | ||
| } |
There was a problem hiding this comment.
Consider using the same method or a central part for both functions as to reduce the number of duplicate lines of code
| System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
| } | ||
|
|
||
| private static void event(String line) { |
There was a problem hiding this comment.
Consider naming the methods better for easy maintainability and scalability
| String from; | ||
| String to; |
There was a problem hiding this comment.
Consider something like fromDate , toDate
| return "[" + | ||
| (isDone ? "X" : " ") + | ||
| "] " + | ||
| task; |
There was a problem hiding this comment.
Consider same line implementation to increase code readability
|
|
||
| public class Utilities { | ||
| public static Hashtable<String, String> getCommandArgument(String line) { | ||
| Hashtable<String, String> args = new Hashtable<>(); |
There was a problem hiding this comment.
Try to not use vague names for variables
No description provided.